package com.sneaker.shower.mapstruct;

import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import com.sneaker.shower.entity.domain.user.UserDO;
import com.sneaker.shower.entity.dto.UserDTO;
import com.sneaker.shower.entity.dto.UserTypeDTO;
import com.sneaker.shower.entity.enums.UserTypeEnum;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
import org.springframework.stereotype.Component;

@Mapper(componentModel = "spring", imports = {UserTypeDTO.class, UserTypeEnum.class})
@Component
public interface UserMapStruct {
    UserMapStruct INSTANCE = Mappers.getMapper(UserMapStruct.class);

    @Mappings({
            @Mapping(target = "userType", expression = "java(new UserTypeDTO(UserTypeEnum.getByCode(userDO.getUserType())))"),
            @Mapping(target = "invitedQrCode", source = "invitedQrCodeUrl")
    })
    UserDTO do2DTO(UserDO userDO);

    @Mappings({
            @Mapping(target = "userType", expression = "java(new UserTypeDTO(UserTypeEnum.getByCode(userDO.getUserType())))"),
            @Mapping(target = "invitedQrCode", expression = "java(userDO.getInvitedQrCodeUrl())")
    })
    UserDTO do2DTO(UserDO userDO, String type);

    UserDO maUser2DO(WxMaUserInfo wxMaUserInfo);

    @Mappings(
            @Mapping(target = "userType", expression = "java(userDTO.getUserType().getCode())")
    )
    UserDO dto2DO(UserDTO userDTO);
}
